package org.example.huawei;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Yyming
 * @version 10.0
 * Created by Yyming on 2021/3/23
 */
public class Main323 {

    public static void main(String[] args) {
        String str = "aabbc";
        StringReader stringReader = new StringReader(str);
        System.out.println(remove("abbc"));
    }


    public static String remove(String str) {
        if (str.length() <= 1) {
            return str;
        }
        //aaabbcda
        StringBuilder builder = new StringBuilder();
        char c = str.charAt(0);
        int count = 1;
        //标记一下有没有重复
        boolean flag = false;
        for (int i = 1; i < str.length(); i++) {
            char cur = str.charAt(i);
            if (cur == c) {
                count++;
                continue;
            } else if (count > 1){
                //重复
                flag = true;
                count = 0;
            } else {
                //不连续
                builder.append(c);
            }
            if (i == str.length() - 1) builder.append(cur);
            c = cur;
        }
        return flag ? remove(builder.toString()) :  builder.toString();
    }


}

